<?php
/**
 * 素材维护计划
 * @author ice<iceinto@mallog.com.cn>
 */
class PlanAction extends BaseAction
{
    public function _initialize()
    {
        parent::_initialize();
        $this->assign('nav', 2);
    }

    public function index()
    {
        $MaintenancePlan = M('MaintenancePlan');
        $allCount = $MaintenancePlan->count();
        $Page = $this->getPage($allCount);
        $plans = $MaintenancePlan->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('itemid DESC')
            ->select();
        $this->assign('plans', $plans);
        $this->assign('page', $Page->show());
        $this->display();
    }

    /**
     * 计划详细
     * @author ice<iceinto@mallog.com.cn>
     */
    public function detail()
    {
        $itemid = intval(getGet('id'));
        $plan = M('MaintenancePlan')->find($itemid);
        $this->assign('plan', $plan);
        $this->display();
    }

    /**
     * 计划任务列表
     * @author ice<iceinto@mallog.com.cn>
     */
    public function task()
    {
        $pid = intval(getGet('id'));
        $Maintenance = D('Maintenance');
        $taskCount = $Maintenance->getPlanCount($pid);
        $Page = $this->getPage($taskCount);
        $tasks = $Maintenance->getPlanTaskList($pid, $Page->firstRow . ',' . $Page->listRows);
        $this->assign('tasks', $tasks);
        $this->assign('page', $Page->show());
        $this->display();
    }

    /**
     * 添加计划
     * @author ice<iceinto@mallog.com.cn>
     */
    public function add()
    {
    }

    /**
     * 获取任务详细
     * @author ice<iceinto@mallog.com.cn>
     */
    public function td()
    {
        $itemid = intval(getGet('id'));
        $maintenance = M('maintenance')->find($itemid);
        $map = array();
        $map['mid'] = $maintenance['itemid'];
        $maintenanceAllot = M('maintenanceAllot')->where($map)->find();
        unset($map);
        $map['itemid'] = $maintenance['pid'];
        $maintenancePlan = M('maintenancePlan')->find($maintenance['pid']);
        $uid = $maintenanceAllot['uid'];
        $user = D('User')->getOne($uid);
        $this->assign('allot', $maintenanceAllot);
        $this->assign('plan', $maintenancePlan);
        $this->assign('task', $maintenance);
        $this->assign('taskUser', $user);
        $this->display();
    }
}